package com.juicygames.shmup.player;

import com.juicygames.framework.action.UpdateAction;
import com.juicygames.framework.handler.UpdateHandler;
import com.juicygames.framework.property.space.Position;

public class Follower extends UpdateHandler {
	
	Position targetPosition;
	Mover mover;
	int speed;
	
	public void load() {
		mover = parent.addPart(new Mover());
	}
	
	public void handle(UpdateAction update) {
		if (targetPosition != null) {
			mover.setVelTowardPoint(targetPosition.get(), speed);
		}
	}
	
	public void follow(Position position, int speed) {
		targetPosition = position;
		this.speed = speed;
	}
	
	public void stopFollowing() {
		targetPosition = null;
		speed = 0;
		mover.stop();
	}

}
